<template>
  <view class="background">
    <view class="img">
      <image src="../../static/loginLogo.png" mode="1212" class="logo"></image>
    </view>
    <view class="formData">
      <formData
        :values="values"
        :fields="fields"
        @confirm="disembark"
        :rules="rules"
        ref="FormData"
        labelAlign="left"
      >
      </formData>
    </view>

    <view class="button_error" @click="disembark"> 登录 </view>
    <view class="bottom">
      <u-checkbox-group active-color="#E24D49">
        <u-checkbox v-model="checked" class="checkbox" size="30" />
      </u-checkbox-group>
      <view class="read"> 已读 </view>
      <view class="tips" @click="treaty"> 《用户协议与隐私政策》 </view>
    </view>
    <u-toast ref="uToast" />
  </view>
</template>


<script>
import FormData from "@/components/form/index";
import toast from "../../utils/toast.js";
import { mapState, mapMutations, mapActions } from "vuex";
export default {
  data() {
    return {
      checked: false,
    };
  },
  components: {
    FormData,
  },
  methods: {
    ...mapMutations({}),
    ...mapActions({
      verificationLogin: "LOGIN/VERIFICATION_LOGIN", //验证码登录
    }),
    disembark() {
      let flag = this.$refs.FormData.submit();
      if (flag) {
        if (!this.checked) {
          this.$u.toast("请仔细阅读用户协议与隐私政策");
          return;
        }
        uni.showLoading({
          title: "加载中",
        });
        this.verificationLogin();
      }
    },
    //查看用户协议
    treaty() {
      uni.navigateTo({
        url: "/pages/login/agreement",
      });
    },
  },
  mounted() {},
  onShow() {
	 
    let token = uni.getStorageSync("token");
	 console.log(token)
    let check_status = uni.getStorageSync("check_status");
    let app_index = uni.getStorageSync("app_index");

    if (token!='') {
      if (check_status == "0") {
        uni.redirectTo({
          url: "/pages/management/waitFor",
        });
      } else if (check_status == 1) {
        uni.switchTab({
          url: "/pages/management/index",
        });
        uni.setStorageSync("flag", true);
      } else if (check_status == 2) {
        uni.switchTab({
          url: "/pages/management/index",
        });
        uni.setStorageSync("flag", false);
      } else if (check_status == 3) {
        uni.redirectTo({
          url: "/pages/management/customer",
        });
        uni.setStorageSync("flag", false);
      } else if (app_index == 1) {
        uni.redirectTo({
          url: "/pages/management/welcome",
        });
      } else {
        uni.switchTab({
          url: "/pages/management/index",
        });
        uni.setStorageSync("flag", false);
      }
    }
  },
  watch: {},
  computed: {
    ...mapState({
      fields: (state) => state.LOGIN.fields,
      values: (state) => state.LOGIN.values,
      rules: (state) => state.LOGIN.rules,
    }),
  },

  onLoad() {},
};
</script>

<style scoped lang='scss'>
.img {
  width: 100%;
  height: 352rpx;
  display: flex;
  justify-content: center;
  align-items: center;

  .logo {
    width: 160rpx;
    height: 160rpx;
  }
}

.formData {
  width: 100%;
  height: 606rpx;
  padding: 0rpx 32rpx;
}

.background {
  background-color: #fff !important;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.button_error {
  width: 686rpx;
  height: 100rpx;
  background: #e24d49;
  border-radius: 10rpx;
  font-size: 32rpx;
  color: #fff;
  margin-top: 94rpx;
  display: flex;
  justify-content: center;
  align-items: center;
}

.password_login {
  margin-top: 28rpx;
  color: #3775f6;
  font-size: 32rpx;
}

.bottom {
  margin-top: 86rpx;
  display: flex;
  width: 686rpx;
  padding-bottom: 20rpx;
  position: relative;
}

.tips {
  height: 44rpx;
  font-size: 24rpx;
  color: #E24D49;
  margin-top: 10rpx;
  margin-left: 10rpx;
}

.read {
  margin-top: 10rpx;
  font-size: 24rpx;
  margin-left: -20rpx;
}
</style>
/* <style>
.uni-app--maxwidth {
  background-color: #ffffff !important;
}
</style> */
